package com.ruoyi.asset.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.AssetInOut;
import com.ruoyi.asset.service.IAssetInOutService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出入库记录Controller
 * 
 * @author yepanpan
 * @date 2024-12-24
 */
@RestController
@RequestMapping("/asset/inOut")
public class AssetInOutController extends BaseController
{
    @Autowired
    private IAssetInOutService assetInOutService;


    /**
     * 查询出入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('asset:inOut:my')")
    @GetMapping("/my")
    public TableDataInfo my(AssetInOut assetInOut)
    {
        assetInOut.setUserId(SecurityUtils.getUserId());
        startPage();
        List<AssetInOut> list = assetInOutService.selectAssetInOutList(assetInOut);
        return getDataTable(list);
    }


    /**
     * 查询出入库记录列表
     */
    @GetMapping("/select")
    public AjaxResult select(AssetInOut assetInOut)
    {
        List<AssetInOut> list = assetInOutService.selectAssetInOutList(assetInOut);
        return success(list);
    }

    /**
     * 查询出入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('asset:inOut:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetInOut assetInOut)
    {
        startPage();
        List<AssetInOut> list = assetInOutService.selectAssetInOutList(assetInOut);
        return getDataTable(list);
    }

    /**
     * 导出出入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('asset:inOut:export')")
    @Log(title = "出入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetInOut assetInOut)
    {
        List<AssetInOut> list = assetInOutService.selectAssetInOutList(assetInOut);
        ExcelUtil<AssetInOut> util = new ExcelUtil<AssetInOut>(AssetInOut.class);
        util.exportExcel(response, list, "出入库记录数据");
    }

    /**
     * 获取出入库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('asset:inOut:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assetInOutService.selectAssetInOutById(id));
    }

    /**
     * 新增出入库记录
     */
    @PreAuthorize("@ss.hasPermi('asset:inOut:add')")
    @Log(title = "出入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetInOut assetInOut)
    {
        return toAjax(assetInOutService.insertAssetInOut(assetInOut));
    }

    /**
     * 修改出入库记录
     */
    @PreAuthorize("@ss.hasPermi('asset:inOut:edit')")
    @Log(title = "出入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetInOut assetInOut)
    {
        return toAjax(assetInOutService.updateAssetInOut(assetInOut));
    }

    /**
     * 删除出入库记录
     */
    @PreAuthorize("@ss.hasPermi('asset:inOut:remove')")
    @Log(title = "出入库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetInOutService.deleteAssetInOutByIds(ids));
    }
}
